package org.termine.entity;

import java.io.InputStream;
import java.io.Serializable;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.LinkedList;
import java.util.List;

import org.primefaces.model.ScheduleEvent;
import org.primefaces.model.map.MapModel;
import org.termine.util.Xml;

public class ClientProviderScheduleEvent implements ScheduleEvent, Serializable {

	private static final long serialVersionUID = 4577114647136026472L;

	private String id;
	private Integer locationId;
	private Integer appointmentId;
	private Date appointmentStart;
	private Integer durationInMin;
	private String serviceName;
	private String serviceDescription;
	private Integer serviceCancelDeadlineInMin;
	private String clientProviderForename;
	private String clientProviderSurname;
	private String clientProviderEmail;
	private String clientProviderPhoneNumber;
	private String locationCountry;
	private String locationCity;
	private String locationZip;
	private String locationStreet;
	private double locationLatitude;
	private double locationLongitude;
	private String xmlCalendar;
	private MapModel mapModel;

	public static InputStream toXCalXml(List<ClientProviderScheduleEvent> appointments) throws Exception {
		List<InputStream> vEvents = new LinkedList<InputStream>();
		for (int i = 0; i < appointments.size(); i++) {
			vEvents.add(Xml.stringToXmlInputStream(appointments.get(i).getXmlCalendar()));
		}
		return Xml.toXCalXml(vEvents);
	}

	/*
	 * ScheduleEvent Overrides
	 */
	@Override
	public void setId(String id) {
		this.id = id;
	}

	@Override
	public Object getData() {
		return this;
	}

	@Override
	public Date getEndDate() {
		Calendar calendar = new GregorianCalendar();
		calendar.setTime(appointmentStart);
		calendar.add(Calendar.MINUTE, durationInMin);
		return calendar.getTime();
	}

	@Override
	public String getId() {
		return id;
	}

	@Override
	public Date getStartDate() {
		return appointmentStart;
	}

	@Override
	public String getStyleClass() {
		return null;
	}

	@Override
	public String getTitle() {
		return serviceName;
	}

	@Override
	public boolean isAllDay() {
		return false;
	}

	@Override
	public boolean isEditable() {
		return false;
	}

	/*
	 * Getters & Setters
	 */
	public Integer getAppointmentId() {
		return appointmentId;
	}

	public double getLocationLatitude() {
		return locationLatitude;
	}

	public void setLocationLatitude(double locationLatitude) {
		this.locationLatitude = locationLatitude;
	}

	public double getLocationLongitude() {
		return locationLongitude;
	}

	public void setLocationLongitude(double locationLongitude) {
		this.locationLongitude = locationLongitude;
	}

	public Integer getLocationId() {
		return locationId;
	}

	public void setLocationId(Integer locationId) {
		this.locationId = locationId;
	}

	public void setAppointmentId(Integer appointmentId) {
		this.appointmentId = appointmentId;
	}

	public Date getAppointmentStart() {
		return appointmentStart;
	}

	public void setAppointmentStart(Date appointmentStart) {
		this.appointmentStart = appointmentStart;
	}

	public String getServiceName() {
		return serviceName;
	}

	public void setServiceName(String serviceName) {
		this.serviceName = serviceName;
	}

	public String getServiceDescription() {
		return serviceDescription;
	}

	public void setServiceDescription(String serviceDescription) {
		this.serviceDescription = serviceDescription;
	}

	public Integer getServiceCancelDeadlineInMin() {
		return serviceCancelDeadlineInMin;
	}

	public void setServiceCancelDeadlineInMin(Integer serviceCancelDeadlineInMin) {
		this.serviceCancelDeadlineInMin = serviceCancelDeadlineInMin;
	}

	public String getLocationCountry() {
		return locationCountry;
	}

	public void setLocationCountry(String locationCountry) {
		this.locationCountry = locationCountry;
	}

	public String getLocationCity() {
		return locationCity;
	}

	public void setLocationCity(String locationCity) {
		this.locationCity = locationCity;
	}

	public String getLocationZip() {
		return locationZip;
	}

	public void setLocationZip(String locationZip) {
		this.locationZip = locationZip;
	}

	public String getLocationStreet() {
		return locationStreet;
	}

	public void setLocationStreet(String locationStreet) {
		this.locationStreet = locationStreet;
	}

	public String getClientProviderForename() {
		return clientProviderForename;
	}

	public void setClientProviderForename(String clientProviderForename) {
		this.clientProviderForename = clientProviderForename;
	}

	public String getClientProviderSurname() {
		return clientProviderSurname;
	}

	public void setClientProviderSurname(String clientProviderSurname) {
		this.clientProviderSurname = clientProviderSurname;
	}

	public String getClientProviderEmail() {
		return clientProviderEmail;
	}

	public void setClientProviderEmail(String clientProviderEmail) {
		this.clientProviderEmail = clientProviderEmail;
	}

	public String getClientProviderPhoneNumber() {
		return clientProviderPhoneNumber;
	}

	public void setClientProviderPhoneNumber(String clientProviderPhoneNumber) {
		this.clientProviderPhoneNumber = clientProviderPhoneNumber;
	}

	public Integer getDurationInMin() {
		return durationInMin;
	}

	public void setDurationInMin(Integer durationInMin) {
		this.durationInMin = durationInMin;
	}

	public MapModel getMapModel() {
		return mapModel;
	}

	public void setMapModel(MapModel mapModel) {
		this.mapModel = mapModel;
	}

	public String getXmlCalendar() {
		return xmlCalendar;
	}

	public void setXmlCalendar(String xmlCalendar) {
		this.xmlCalendar = xmlCalendar;
	}
	
}
